using System;

namespace YAFTS.Core.Model
{
	internal class StringWrapper : IEquatable<StringWrapper>
	{
		private string _value;

		protected StringWrapper(string value)
		{
			_value = string.Intern(value);
		}

		protected string Value
		{
			get { return _value; }
			set { _value = string.Intern(value); }
		}

		public bool Equals(StringWrapper other)
		{
			if (ReferenceEquals(null, other))
			{
				return false;
			}
			if (ReferenceEquals(this, other))
			{
				return true;
			}
			return Equals(other._value, _value);
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj))
			{
				return false;
			}
			if (ReferenceEquals(this, obj))
			{
				return true;
			}
			
			return Equals((StringWrapper) obj);
		}

		public override int GetHashCode()
		{
			return (_value != null ? _value.GetHashCode() : 0);
		}

		public static bool operator ==(StringWrapper left, StringWrapper right)
		{
			return Equals(left, right);
		}

		public static bool operator !=(StringWrapper left, StringWrapper right)
		{
			return !Equals(left, right);
		}

		public override string ToString()
		{
			return string.Format("{0}: {1}", GetType().Name, _value);
		}
	}
}